﻿using Android.Content;
using Android.Net.Http;
using Android.Print;
using Android.Webkit;
using Java.Net;
using Microsoft.Maui.Platform;
using System.Net;

namespace ZXAPP
{
    public class CustomWebViewClient : WebViewClient
    {
        public override void OnPageFinished(Android.Webkit.WebView view, string url)
        {
            base.OnPageFinished(view, url);
            view.Settings.JavaScriptEnabled = true;//启用js

        }

        public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
        {
            string url = request.Url.ToString();
            if (url.StartsWith("app://"))
            {
                var pageName = url.Substring(6);
                //var pages = Navigation.NavigationStack;
                // 根据页面的名字导航到不同的页面
                if (pageName == "splashpage")
                {
                    Task.Run(() => { 
                        Shell.Current.GoToAsync("//splashpage");
                    });
                }
                return true; 
            }


            return false; // 没有处理 URL 加载，让 WebView 正常加载
        }

        public override void OnReceivedSslError(Android.Webkit.WebView view, SslErrorHandler handler, SslError error)
        {
            handler.Proceed();
        }
    }
}